home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 512 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: sequence pts wrt pointer dereferencing
  5. Date: Sat, 06 Jan 96 13:20:41 GMT
  6. Organization: none
  7. Message-ID: <820934441snz@genesis.demon.co.uk>
  8. References: <optimal.8.7116A605@vir.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <optimal.8.7116A605@vir.com> optimal@vir.com "optimal" writes:
  15.  
  16. >For reasons of virtual memory swapping, we have what amounts to the following:
  17. >
  18. >int* A (int i)
  19. >   {
  20. >   static int x;
  21. >
  22. >   x = i;
  23. >   return &x;
  24. >   }
  25. >
  26. >foo ( )
  27. >   {
  28. >   .....
  29. >   *A(1) += *A(100);
  30. >   }
  31.  
  32. This doesn't make much sense. What exactly are you trying to buy yourself
  33. in a 'virtual memory swapping' environment by doing this? I assume this code
  34. isn't run at an ordinary 'user' level since virtual memory is transparent
  35. to such code. If you're expecting object addresses to change under your feet
  36. then I doubt whether any C code will last very long.
  37.  
  38. >This fails due to the value *A(100) not being stored before the *A(1) is 
  39. >evaulated. The following works:
  40. >
  41. >   int tmp = *A(100);
  42. >   *A(1) += tmp;
  43.  
  44. This seems to be a very long-winded way of storing 101 in a static variable.
  45. Explain why this could result in different behaviour to:
  46.  
  47.     A(1+100);
  48.  
  49. >Is there another alternative to the use of tmp variables?
  50.  
  51. Possibly, but you need to state your constraints. For instance the following
  52. may be what you are looking for, but then possibly not.
  53.  
  54. int* A1 (int i)
  55.    {
  56.    static int x;
  57.  
  58.    x = i;
  59.    return &x;
  60.    }
  61.  
  62. int* A2 (int i)
  63.    {
  64.    static int x;
  65.  
  66.    x = i;
  67.    return &x;
  68.    }
  69.  
  70. foo ( )
  71.    {
  72.    .....
  73.    *A1(1) += *A2(100);
  74.    }
  75.  
  76. -- 
  77. -----------------------------------------
  78. Lawrence Kirby | fred@genesis.demon.co.uk
  79. Wilts, England | 70734.126@compuserve.com
  80. -----------------------------------------
  81.